<?php
$navArray = Navigator::findAll();
$linkArray = Link::findAll();
$categoryArray = Category::findAll();
$settings = Config::getInstance();
$tagArray = Tag::findAll();

$base = $settings->get('base');
$theme = $settings->get('theme');
?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title><?php echo $settings->get('title'); ?></title>
    <script src="<?php echo $base ?>/themes/<?php echo $theme ?>/scripts/html5.js"></script>
    <link  href="<?php echo $base ?>/themes/<?php echo $theme ?>/styles/normalize.css" rel="stylesheet" />
    <link  href="<?php echo $base ?>/themes/<?php echo $theme ?>/styles/article.css" rel="stylesheet" />
    <link  href="<?php echo $base ?>/themes/<?php echo $theme ?>/styles/index.css" rel="stylesheet" />
</head>
<body>
<header>
    <h1><span><a href="<?php echo $base; ?>"><?php echo $settings->get('title') ?></a></span></h1>

    <p><?php echo $settings->get('description') ?></p>
    <nav>
        <ul>
            <?php
            foreach ($navArray as /** @var $nav Navigator */ $nav) {
            ?>
            <li><a href="<?php echo $nav->getHref() ?>" target="<?php echo $nav->getTarget() ?>"><?php echo $nav->getName() ?>&nbsp;</a></li>
            <?php
            }
            ?>
        </ul>
    </nav>
</header>
<div id="content-wrapper">
    <aside>
        <nav>
            <h1>分类</h1>
            <ul>
                <?php foreach ($categoryArray as /** @var $category Category */ $category) { ?>
                <li><a href="<?php echo $base, '/category/', $category->getName(), '.html' ?>" title="查看 <?php echo $category->getName() ?> 的全部文章"><?php echo $category->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav class="tag-nav">
            <h1>标签</h1>
            <ul>
                <?php foreach ($tagArray as /** @var $tag Tag */ $tag) { ?>
                <li><a href="<?php echo $base, '/tag/', $tag->getName(), '.html' ?>"><?php echo $tag->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav>
            <h1>链接</h1>
            <ul>
                <?php foreach ($linkArray as /** @var $link Link */ $link) { ?>
                <li><a href="<?php echo $link->getHref() ?>" target="_blank" title="<?php echo $link->getDescription() ?>"><?php echo $link->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
    </aside>
    <section>
        <?php
        foreach ($GLOBALS['posts'] as /** @var Post $post */ $post) {
        ?>
        <article class="post blog-content">
            <header class="post-header">
                <h2><a href="<?php echo $base ?>/post/<?php echo $post->getId() ?>.html" title="<?php echo $post->getTitle() ?>"><?php echo $post->getTitle() ?></a></h2>

                <p>
                <?php echo date('Y-m-d H:i:s', intval($post->getCreateTime())); ?> |
                <?php echo $post->getAuthor() ?> |
                <a href="<?php echo $base; ?>/post/<?php echo $post->getId() ?>.html#comments" title="查看评论"><?php echo count($post->getComments()) ?> Comments</a> |
                <?php 
                $categoryName = Category::findById($post->getCategory())->getName();
                echo sprintf('<a href="%s/category/%s.html" title="查看 %s 的全部文章">%s</a>', $base, $categoryName, $categoryName, $categoryName);

                if (count($post->getTags()) == 0) {
                } else {
                    echo ' | ';
                    foreach ($post->getTags() as $tag) {
                        echo sprintf('<a href="%s/tag/%s.html" title="所属标签 %s">%s</a>&nbsp;', $base, $tag, $tag, $tag);
                    }
                }
                ?></p>
            </header>
            <div>
                <?php echo $post->getContent() ?>
            </div>
        </article>
        <?php } ?>
    </section>
    <nav>
        <ul>
            <?php if ($GLOBALS['page-prev'] !== false) { ?>
            <li class="prev-page"><a href="<?php echo $base, $GLOBALS['url'], '_', $GLOBALS['page-prev'], '.html' ?>">上一页</a></li>
            <?php } ?>
            <?php if ($GLOBALS['page-next'] !== false) { ?>
            <li class="next-page"><a href="<?php echo $base, $GLOBALS['url'], '_', $GLOBALS['page-next'], '.html' ?>">下一页</a></li>
            <?php } ?>
        </ul>
    </nav>
</div>
<footer>
    <p><a href="http://paperblog.showframework.com/">Powered by Paper Blog</a></p>
</footer>
</body>
</html>
